<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class TingcheController extends AdminbaseController{
    
    protected $menu_model;
    protected $model_cwarea;
    protected $model_clguanli;
    protected $model_chewei;


    function _initialize() {
        parent::_initialize();
        $this->model_cwarea = M("cwarea");
        $this->model_chewei=M("chewei");
        $this->model_clguanli=M("clguanli");
        $this->menu_model=M('xiaoqu');

    }
    
    function carArea(){
        	
            $info=$this->model_cwarea->select();
            
            $this->assign('info', $info);
		
	
        
        $this->display();
        
    }
    
    function  carManager(){
         $cheliang=$this->model_clguanli->select();
            
            $this->assign('cheliang', $cheliang);
        
        $this->display();
        
    }
    function cheweiManager(){
         $chewei=$this->model_chewei->select();
            
            $this->assign('chewei', $chewei);
        
        $this->display();
        
    }
    
    function cw_add(){
          $uid=get_current_admin_id();
       $xqs= $this->menu_model->where('uid=%d',$uid)->select();
        
       $this->assign('xqs',$xqs);
        
       $this->display(); 
    }
    function cl_add(){
         $uid=get_current_admin_id();
       $xqs= $this->menu_model->where('uid=%d',$uid)->select();
        
       $this->assign('xqs',$xqs);
        
        $this->display();
        
    }
    
    function area_add(){
          $uid=get_current_admin_id();
       $xqs= $this->menu_model->where('uid=%d',$uid)->select();
        
       $this->assign('xqs',$xqs);
     $this->display();   
        
    }
    
    function area_addPost(){
           	if (IS_POST) {
    		if ($this->model_cwarea->create()) {
    			if ($this->model_cwarea->add()!==false) {
                         
                            
                               $this->model_cwarea->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->model_cwarea->getError());
    		}
               
    	}
    }
        function cl_addPost(){
           	if (IS_POST) {
    		if ($this->model_clguanli->create()) {
    			if ($this->model_clguanli->add()!==false) {
                         
                           
                               $this->model_clguanli->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->model_clguanli->getError());
    		}
               
    	}
    }
        function cw_addPost(){
           	if (IS_POST) {
    		if ($this->model_chewei->create()) {
    			if ($this->model_chewei->add()!==false) {
                         
                            
                               $this->model_chewei->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->model_chewei->getError());
    		}
               
    	}
    }
     function area_delete(){
        $id = intval(I("get.id")); 
          $count = $this->model_cwarea->where(array("parentid" => $id))->count();
    
        if ($this->model_cwarea->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
     }
       function car_delete(){
        $id = intval(I("get.id")); 
          $count = $this->model_clguanli->where(array("parentid" => $id))->count();
    
        if ($this->model_clguanli->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
     }
       function chewei_delete(){
        $id = intval(I("get.id")); 
          $count = $this->model_chewei->where(array("parentid" => $id))->count();
    
        if ($this->model_chewei->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
     }
         function updata(){
 
        $id = intval(I("get.id"));
        $res=$this->menu_model->where('id=%d',array($id))->select();
       $this->assign('res', $res);
        $this->display(); 
        
        
    }
      function cwadd_change(){
          $lys=$this->model_cwarea->where("xqid=%d",$_POST['id'])->select();
         $php_json = json_encode($lys); 

        echo $php_json;
    }
     function cladd_change(){
          $lys=$this->model_chewei->where("areaid=%d",$_POST['id'])->select();
         $php_json = json_encode($lys); 

        echo $php_json;
    }
}